<template>
  <el-container style="height: 100vh;">
    <!-- 侧边菜单 -->
    <el-aside width="220px" class="sidebar">
      <div class="logo">
        <el-icon size="32" color="#21b26b"><UserFilled /></el-icon>
        <span class="title">智慧会议管理平台</span>
      </div>
      <el-menu
        :default-active="activeMenu"
        class="el-menu-vertical-demo"
        background-color="#111"
        text-color="#fff"
        active-text-color="#2196f3"
        @select="handleMenuSelect"
        router
      >
        <el-menu-item index="home">
          <el-icon><OfficeBuilding /></el-icon>
          <span>首页</span>
        </el-menu-item>
        <el-menu-item index="meeting-list">
          <el-icon><List /></el-icon>
          <span>会议室管理</span>
        </el-menu-item>
        <el-menu-item index="/appointment">
          <el-icon><Calendar /></el-icon>
          <span>会议预约</span>
        </el-menu-item>
        <el-menu-item index="audit">
          <el-icon><DocumentChecked /></el-icon>
          <span>会议审批</span>
        </el-menu-item>
        <!-- <el-menu-item index="stat">
          <el-icon><DataAnalysis /></el-icon>
          <span>统计分析</span>
        </el-menu-item> -->
        <el-sub-menu index="sys">
          <template #title>
            <el-icon><Setting /></el-icon>
            <span>系统管理</span>
          </template>
          <el-menu-item index="/SysUserView">用户管理</el-menu-item>
          <el-menu-item index="sys-role">角色权限</el-menu-item>
          <el-menu-item index="sys-dept">部门管理</el-menu-item>
          <el-menu-item index="sys-log">操作日志</el-menu-item>
        </el-sub-menu>
      </el-menu>
    </el-aside>

    <!-- 主体内容 -->
    <el-container>
      <!-- 顶部栏 -->
      <el-header class="header">
        <div class="user-info">
          <span>欢迎，{{ user.NickName }}</span>
          <el-button type="danger" size="small" @click="logout" style="margin-left: 20px;">退出登录</el-button>
        </div>
      </el-header>
      <el-main class="main-content">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { useCounterStore } from '@/stores/counter'
import { ElMessage } from 'element-plus'
import {
  UserFilled, OfficeBuilding, Calendar, DocumentChecked, DataAnalysis, Setting, List
} from '@element-plus/icons-vue'

const store = useCounterStore()
const user = computed(() => ({
  NickName: store.UserInfo.NickName,
  RoleName: (store.UserInfo as any).RoleName || '普通用户'
}))

const router = useRouter()
const activeMenu = ref('home')

function handleMenuSelect(index: string) {
  activeMenu.value = index
  router.push(index)
}

function logout() {
  store.UserInfo.Token = ''
  store.UserInfo.NickName = ''
  store.UserInfo.UserId = 0
  sessionStorage.removeItem('token')
  ElMessage.success('已退出登录')
  router.replace('/')
}
</script>

<style scoped>
.sidebar {
  background: #111;
  color: #fff;
  min-height: 100vh;
  border-right: 1px solid #eee;
  padding: 0;
}
.logo {
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 20px;
  font-size: 20px;
  font-weight: bold;
  color: #21b26b;
}
.logo .title {
  margin-left: 10px;
  color: #fff;
  font-size: 18px;
  font-weight: bold;
}
.header {
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 64px;
  border-bottom: 1px solid #eee;
}
.user-info {
  font-size: 16px;
  color: #333;
  display: flex;
  align-items: center;
}
.main-content {
  background: #f5f7fa;
  min-height: calc(100vh - 64px);
  padding: 24px;
}
</style> 